import 'package:flutter/material.dart';

class RouteJumpReturnsData extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('页面跳转并返回数据'),
      ),
      body: FirstPage(),
    );
  }
}

class FirstPage extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Center(
      child: RouteButton(),
    );
  }
}

class RouteButton extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return RaisedButton(
      onPressed: () {
        _navigateToSecondPage(context);
      },
      child: Text('跳转到第二个页面'),
    );
  }

  _navigateToSecondPage(BuildContext context) async {
    final result = await Navigator.push(
        context, MaterialPageRoute(builder: (context) => SecondPage()));
    Scaffold.of(context).showSnackBar(SnackBar(content: Text('$result'),));
  }
}

class SecondPage extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('第二个界面'),
      ),
      body: Center(
        child: Column(
          children: <Widget>[
            RaisedButton(
              child: Text('第一个按钮'),
              onPressed: () {
                Navigator.pop(context, '点击了第一个按钮');
              },
            ),
            RaisedButton(
              child: Text('第二个按钮'),
              onPressed: () {
                Navigator.pop(context, '点击了第二个按钮');
              },
            ),
            RaisedButton(
              child: Text('第三个按钮'),
              onPressed: () {
                Navigator.pop(context, '点击了第三个按钮');
              },
            ),
          ],
        ),
      ),
    );
  }
}
